package com.zito.health.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zito.health.common.annotations.ResponseResult;
import com.zito.health.common.result.PageResult;
import com.zito.health.common.result.VerifyResult;
import com.zito.health.entity.Extension;
import com.zito.health.entity.ExtensionTrain;
import com.zito.health.service.ExtensionService;
import com.zito.health.service.ExtensionTrainService;
import com.zito.health.vo.ExtensionTrainVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description:
 * @author: Sam
 * @time: 2020/03/13 17:42
 */
@Slf4j
@ResponseResult
@RestController
@RequestMapping("/extensionTrain")
public class ExtensionTrainController {

    @Autowired
    private ExtensionTrainService extensionTrainService;

    @GetMapping
    public PageResult list(ExtensionTrainVo param, @RequestParam(defaultValue = "0") Integer pageNo, @RequestParam(defaultValue = "10")Integer pageSize){
        PageResult<ExtensionTrainVo> result = new PageResult();
        if(pageNo!=null&&pageSize!=null){
            PageHelper.startPage(pageNo, pageSize);
        }
        List<ExtensionTrainVo> list = extensionTrainService.queryList(param);
        PageInfo<ExtensionTrainVo> pageInfo = new PageInfo<ExtensionTrainVo>(list);
        result.setTotal(pageInfo.getTotal());
        result.setRows(pageInfo.getList());
        return result;
    }


    /**
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ExtensionTrainVo queryById(@PathVariable Integer id){
        ExtensionTrainVo vo = extensionTrainService.selectById(id);
        return vo;
    }

    @PostMapping
    public VerifyResult save(ExtensionTrain extensionTrain) {
        VerifyResult verifyResult = new VerifyResult();
        extensionTrainService.save(extensionTrain);
        return verifyResult;
    }

    @PutMapping
    public VerifyResult update(ExtensionTrain extensionTrain){
        VerifyResult verifyResult = new VerifyResult();
        extensionTrainService.update(extensionTrain);
        return verifyResult;
    }


    @DeleteMapping("/{id}")
    public VerifyResult delete(@PathVariable Integer id){
        VerifyResult verifyResult = new VerifyResult();
        extensionTrainService.delete(id);
        return verifyResult;
    }


}
